]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
st/icon: Add :is-symbolic property
authorFlorian Müllner <fmuellner@gnome.org>
Wed, 8 May 2024 10:56:54 +0000 (12:56 +0200)
committerMarge Bot <marge-bot@gnome.org>
Thu, 9 May 2024 17:47:32 +0000 (17:47 +0000)
It can be useful to know whether an icon displays a symbolic (rather
than just requesting it). Add a new :is-symbolic property for that
purpose, backed by private API on StImageContent that allows the
texture cache to shuffle that information through to the icon.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3296>

src/st/st-icon.c
src/st/st-icon.h
src/st/st-image-content-private.h [new file with mode: 0644]
src/st/st-image-content.c
src/st/st-texture-cache.c

index c9e29ee3f01a9ecef05974292efa3cab169df943..122999893ebf0b3b5a76a680d5c411292afe423a 100644 (file)
@@ -31,6 +31,7 @@
 #include "st-texture-cache.h"
 #include "st-theme-context.h"
 #include "st-private.h"
+#include "st-image-content-private.h"
 
 enum
 {
@@ -43,6 +44,8 @@ enum
   PROP_ICON_SIZE,
   PROP_FALLBACK_ICON_NAME,
 
+  PROP_IS_SYMBOLIC,
+
   N_PROPS
 };
 
@@ -62,6 +65,7 @@ struct _StIconPrivate
   GIcon           *fallback_gicon;
   gboolean         needs_update;
   gboolean         is_themed;
+  gboolean         is_symbolic;
 
   StIconColors     *colors;
 
@@ -155,6 +159,10 @@ st_icon_get_property (GObject    *gobject,
       g_value_set_string (value, st_icon_get_fallback_icon_name (icon));
       break;
 
+    case PROP_IS_SYMBOLIC:
+      g_value_set_boolean (value, st_icon_get_is_symbolic (icon));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
       break;
@@ -359,6 +367,18 @@ st_icon_class_init (StIconClass *klass)
                          NULL,
                          ST_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
 
+  /**
+   * StIcon:symbolic:
+   *
+   * Whether the #StIcon is symbolic.
+   */
+  props[PROP_IS_SYMBOLIC] =
+    g_param_spec_boolean ("is-symbolic",
+                          "Is Symbolic",
+                          "Whether the icon is symbolic",
+                          FALSE,
+                          ST_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY);
+
   g_object_class_install_properties (object_class, N_PROPS, props);
 }
 
@@ -428,12 +448,33 @@ st_icon_update_shadow_pipeline (StIcon *icon)
     }
 }
 
+static void
+st_icon_update_is_symbolic (StIcon *icon)
+{
+  StIconPrivate *priv = icon->priv;
+  gboolean is_symbolic = FALSE;
+  ClutterContent *content = NULL;
+
+  if (priv->icon_texture)
+    content = clutter_actor_get_content (priv->icon_texture);
+
+  if (ST_IS_IMAGE_CONTENT (content))
+    is_symbolic = st_image_content_get_is_symbolic (ST_IMAGE_CONTENT (content));
+
+  if (priv->is_symbolic != is_symbolic)
+    {
+      priv->is_symbolic = is_symbolic;
+      g_object_notify_by_pspec (G_OBJECT (icon), props[PROP_IS_SYMBOLIC]);
+    }
+}
+
 static void
 on_content_changed (ClutterActor *actor,
                     GParamSpec   *pspec,
                     StIcon       *icon)
 {
   st_icon_clear_shadow_pipeline (icon);
+  st_icon_update_is_symbolic (icon);
 }
 
 static void
@@ -459,6 +500,7 @@ st_icon_finish_update (StIcon *icon)
       g_object_unref (priv->icon_texture);
 
       st_icon_clear_shadow_pipeline (icon);
+      st_icon_update_is_symbolic (icon);
 
       g_signal_connect_object (priv->icon_texture, "notify::content",
                                G_CALLBACK (on_content_changed), icon, 0);
@@ -879,3 +921,17 @@ st_icon_set_fallback_icon_name (StIcon      *icon,
 
   g_object_thaw_notify (G_OBJECT (icon));
 }
+
+/**
+ * st_icon_get_is_symbolic:
+ * @icon: an #StIcon
+ *
+ * Returns: Whether the displayed icon is symbolic
+ */
+gboolean
+st_icon_get_is_symbolic (StIcon *icon)
+{
+  g_return_val_if_fail (ST_IS_ICON (icon), FALSE);
+
+  return icon->priv->is_symbolic;
+}
index 8714ef931cbc3088408b38a04a6c082bcf4c106f..2b27ec8af1996a4339546a1e638545dfd246df1e 100644 (file)
@@ -76,6 +76,8 @@ gint         st_icon_get_icon_size (StIcon *icon);
 void         st_icon_set_icon_size (StIcon *icon,
                                     gint    size);
 
+gboolean     st_icon_get_is_symbolic (StIcon *icon);
+
 G_END_DECLS
 
 #endif /* _ST_ICON */
diff --git a/src/st/st-image-content-private.h b/src/st/st-image-content-private.h
new file mode 100644 (file)
index 0000000..b68082a
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * st-image-content-private.h: Private StImageContent methods
+ *
+ * Copyright 2024 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU Lesser General Public License,
+ * version 2.1, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include "st-image-content.h"
+
+G_BEGIN_DECLS
+
+void st_image_content_set_is_symbolic (StImageContent *content,
+                                       gboolean        is_symbolic);
+
+gboolean st_image_content_get_is_symbolic (StImageContent *content);
+
+G_END_DECLS
index 01a39f4f2a517e9944323243dae96cc00b00c591..9ab48f96e8e8f53632e80776d75cbab5f4ecd5b9 100644 (file)
@@ -18,7 +18,7 @@
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "st-image-content.h"
+#include "st-image-content-private.h"
 #include "st-private.h"
 
 #include <gdk-pixbuf/gdk-pixbuf.h>
@@ -34,6 +34,7 @@ struct _StImageContentPrivate
 {
   int width;
   int height;
+  gboolean is_symbolic;
 };
 
 enum
@@ -346,3 +347,26 @@ st_image_content_new_with_preferred_size (int width,
                        "preferred-height", height,
                        NULL);
 }
+
+void
+st_image_content_set_is_symbolic (StImageContent *content,
+                                  gboolean        is_symbolic)
+{
+  StImageContentPrivate *priv;
+
+  g_return_if_fail (ST_IS_IMAGE_CONTENT (content));
+
+  priv = st_image_content_get_instance_private (content);
+  priv->is_symbolic = is_symbolic;
+}
+
+gboolean
+st_image_content_get_is_symbolic (StImageContent *content)
+{
+  StImageContentPrivate *priv;
+
+  g_return_val_if_fail (ST_IS_IMAGE_CONTENT (content), FALSE);
+
+  priv = st_image_content_get_instance_private (content);
+  return priv->is_symbolic;
+}
index b93db94b5a37e3a8b1dd3b09eee785d4a1e7f009..a137480ad1754927e35ac518186f7e12980ae368 100644 (file)
@@ -21,7 +21,7 @@
 
 #include "config.h"
 
-#include "st-image-content.h"
+#include "st-image-content-private.h"
 #include "st-texture-cache.h"
 #include "st-private.h"
 #include "st-settings.h"
@@ -724,6 +724,10 @@ finish_texture_load (AsyncTextureLoadData *data,
         goto out;
     }
 
+  if (data->icon_info)
+    st_image_content_set_is_symbolic (ST_IMAGE_CONTENT (image),
+                                      st_icon_info_is_symbolic (data->icon_info));
+
   for (iter = data->actors; iter; iter = iter->next)
     {
       ClutterActor *actor = iter->data;